﻿using OA.Core.Attribute;
using OA.Core.Helper;
using OA.Core.Model;
using OA.Core.Other;
using Microsoft.AspNetCore.Html;
using Microsoft.AspNetCore.Mvc.ModelBinding;
using Microsoft.AspNetCore.Mvc.Rendering;
using Microsoft.AspNetCore.Mvc.ViewFeatures;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Linq.Expressions;
using System.Reflection;
using System.Text;
using OA.Model.MyAttribute;
using OA.Model;
using System.Net;
using OA.Model.DB;
using OA.Model.Other;
using OA.Model.Result;

namespace OA.AspNetCore.Html
{

   
    public static class MvcHtmlExtension
    {
        private static IHtmlContent MetaDataFor<TModel, TValue>(this IHtmlHelper<TModel> html, Expression<Func<TModel, TValue>> expression, Func<ModelMetadata, string> property)
        {
            if (html == null) throw new ArgumentNullException(nameof(html));
            if (expression == null) throw new ArgumentNullException(nameof(expression));

            ModelExpressionProvider modelExpressionProvider = (ModelExpressionProvider)html.ViewContext.HttpContext.RequestServices.GetService(typeof(IModelExpressionProvider));

            var modelExplorer = modelExpressionProvider.CreateModelExpression(html.ViewData, expression);
            if (modelExplorer == null) throw new InvalidOperationException($"Failed to get model explorer for {modelExpressionProvider.GetExpressionText(expression)}");

            return new HtmlString(property(modelExplorer.Metadata));
        }

        public static IHtmlContent GetMyLabelControl<TModel, TValue>(this IHtmlHelper<TModel> html, Expression<Func<TModel, TValue>> expression)
        {
            return html.MetaDataFor(expression, m => m.DisplayName ?? m.Name);
        }

        public static IHtmlContent DescriptionFor<TModel, TValue>(this IHtmlHelper<TModel> html, Expression<Func<TModel, TValue>> expression)
        {
            return html.MetaDataFor(expression, m => m.Description ?? m.Name);
        }

        public static string GetMyEditorControl(string name, string value, string tips)
        {
            return $"<input type=\"text\" name=\"{name}\" lay-verify=\"required|myText\" autocomplete=\"off\" placeholder=\"{tips}\" class=\"layui-input {name}\" value=\"{value}\" />";
        }

        public static IHtmlContent GetPositionControl(string name, string value, string tips)
        {
            string itemID = name.Replace(".", "_").Replace("[", "_").Replace("]", "_");
            return new HtmlString("<div id=\"" + itemID + "\" class=\"xm-select-position\" data-tips=\"" + tips + "\" data-value=\"" + value + "\" data-name=\"" + name + "\"></div>");
        }

        public static IHtmlContent GetEmployeeControl(string name, string value, string tips)
        {
            string itemID = name.Replace(".", "_").Replace("[", "_").Replace("]", "_");
            return new HtmlString("<div id=\"" + itemID + "\" class=\"xm-select-employee\" data-tips=\"" + tips + "\" data-value=\"" + value + "\" data-name=\"" + name + "\"></div>");
        }

        public static IHtmlContent GetDepartmentControl(string name, string value, string tips)
        {
            string itemID = name.Replace(".", "_").Replace("[", "_").Replace("]", "_");
            return new HtmlString("<div id=\"" + itemID + "\" class=\"xm-select-department\" data-tips=\"" + tips + "\" data-value=\"" + value + "\" data-name=\"" + name + "\"></div>");
        }

        public static string GetMyEditorControl(ExtendField model, string prefix, bool disabled = false)
        {
            List<ListItem> List = null;
            if (!string.IsNullOrWhiteSpace(model.Values))
            {
                if (model.Values == "0")
                {
                    List = new List<ListItem>() { new ListItem() { Text = "请选择", Value = "0" } };
                }
                else if (model.Values.StartsWith("http://") || model.Values.StartsWith("https://"))
                {
                    try
                    {
                        WebClient wc = new WebClient();
                        wc.Encoding = Encoding.UTF8;
                        string result = wc.DownloadString(model.Values);
                        model.ThirdPartyDataSource = result;
                        List = JsonHelper.DeserializeList<ListItem>(result);
                    }
                    catch (Exception ex)
                    {
                        List = new List<ListItem>() { new ListItem() { Text = ex.Message, Value = "0" } };
                    }
                }
                else if (model.Values.ToLower().StartsWith("sql:"))
                {
                    try
                    {
                        using (var dbContext = new MyDbContext())//--- sql注入
                        {
                            
                            var result = "[" + dbContext.Database.SqlQuery<StringBase>(model.Values.Substring(4).Replace("'", "") + " FOR JSON AUTO, INCLUDE_NULL_VALUES,WITHOUT_ARRAY_WRAPPER",null).FirstOrDefault() + "]";
                            model.ThirdPartyDataSource = result;
                            List = JsonHelper.DeserializeList<ListItem>(result);
                        }
                    }
                    catch (Exception ex)
                    {
                        List = new List<ListItem>() { new ListItem() { Text = ex.Message, Value = "0" } };
                    }
                }
                else
                {
                    List = model.Values.Split(new string[] { ",", "，" }, StringSplitOptions.RemoveEmptyEntries).ToList().Select(m => new ListItem() { Text = m, Value = m }).ToList();
                }
            }
            string propertyName = model.Attribute;
            if (!string.IsNullOrWhiteSpace(prefix))
            {
                propertyName = prefix + propertyName;
            }

            //tableValues.RowValues[0].CellValues.__StartLocation
            //dicExtend._K
            //Title
            string className = string.Empty;
            if (propertyName.StartsWith("dicExtend."))
            {
                className = propertyName.Replace("dicExtend.", "");
            }
            else if (propertyName.StartsWith("tableValues"))
            {
                int lastIndex = propertyName.LastIndexOf("__");
                className = propertyName.Substring(lastIndex);
            }
            else
            {
                className = propertyName;
            }
            string verify = string.Empty;
            if(model.IsRequired)
            {
                verify = "required";
            }
            switch (model.Type)
            {
                case (int)TagEnum.Text:
                    return GetTextControl(propertyName, model.Value, className, model.Tips, verify, model.Min, model.Max, disabled).ToString();
                case (int)TagEnum.Phone:
                    if (!string.IsNullOrWhiteSpace(verify)) { verify += "|"; }
                    verify += "phone";
                    return GetTextControl(propertyName, model.Value, className, model.Tips, verify, model.Min, model.Max, disabled).ToString();
                case (int)TagEnum.Url:
                    if (!string.IsNullOrWhiteSpace(verify)) { verify += "|"; }
                    verify += "url";
                    return GetTextControl(propertyName, model.Value, className, model.Tips, verify, model.Min, model.Max, disabled).ToString();
                case (int)TagEnum.Identity:
                    if (!string.IsNullOrWhiteSpace(verify)) { verify += "|"; }
                    verify += "identity";
                    return GetTextControl(propertyName, model.Value, className, model.Tips, verify, model.Min, model.Max, disabled).ToString();
                case (int)TagEnum.Number:
                    return GetNumberControl(propertyName, model.Value, className, model.Tips, verify, model.Min, model.Max, disabled).ToString();
                case (int)TagEnum.Money:
                     return GetMoneyControl(propertyName, model.Value, className, model.Tips, verify, model.Min, model.Max, disabled).ToString();
                case (int)TagEnum.Subtotal:
                    return GetMoneyControl(propertyName, model.Value, className, model.Tips, verify, model.Min, model.Max, disabled).ToString();

                case (int)TagEnum.Calculate:
                    return GetCalculateControl(propertyName, model.Value, className, model.Tips, verify, model.Min, model.Max, disabled).ToString();

                case (int)TagEnum.PassWord:
                    return GetPassWordControl(propertyName, model.Value, className, model.Tips, verify, disabled).ToString();
                case (int)TagEnum.Select:
                    return GetSelectControl(propertyName, model.Value, className, model.Tips, verify, List, model.ThirdPartyDataSource, disabled).ToString();

                case (int)TagEnum.Select2:
                    return GetNumberSelectControl(propertyName, model.Value, className, model.Tips, verify, List, model.ThirdPartyDataSource, disabled).ToString();

                case (int)TagEnum.Radio:
                    return GetRadioControl(propertyName, model.Value, model.Tips, verify, List, disabled).ToString();
                case (int)TagEnum.CheckBox:
                    return GetCheckBoxControl(propertyName, model.Value, model.Tips, verify, List, disabled).ToString();
                case (int)TagEnum.Switch:
                    return GetSwitchControl(propertyName, model.Value, model.Tips, verify, disabled).ToString();
                case (int)TagEnum.Date:
                    return GetDateControl(propertyName, model.Value, className, model.Tips, verify).ToString();
                case (int)TagEnum.Time:
                    return GetTimeControl(propertyName, model.Value, className, model.Tips, verify).ToString();
                case (int)TagEnum.DateTime:
                    return GetDateTimeControl(propertyName, model.Value, className, model.Tips, verify, disabled).ToString();

                case (int)TagEnum.YearMonth:
                    return GetYearMonthControl(propertyName, model.Value, className, model.Tips, verify).ToString();
                case (int)TagEnum.Year:
                    return GetYearControl(propertyName, model.Value, className, model.Tips, verify).ToString();

                case (int)TagEnum.Department:
                    return GetSelectDepartmentControl(propertyName, model.Value, model.Tips, verify, disabled).ToString();

                case (int)TagEnum.Position:
                    return GetSelectPositionControl(propertyName, model.Value, model.Tips, verify, disabled).ToString();

                case (int)TagEnum.Employee:
                    return GetSelectEmployeeControl(propertyName, model.Value, model.Tips, verify, disabled).ToString();



                case (int)TagEnum.TextArea:
                    return GetTextAreaControl(propertyName, model.Value, className, model.Tips, verify, disabled).ToString();
                case (int)TagEnum.RichTextEditor:
                    return GetRichTextEditorControl(propertyName, model.Value, model.Tips, verify, disabled).ToString();
                case (int)TagEnum.SingleImageUpload:
                    return GetImageUploadControl(propertyName, model.Value, model.Tips, verify, false).ToString();
                case (int)TagEnum.MultipleImageUpload:
                    return GetImageUploadControl(propertyName, model.Value, model.Tips, verify, true).ToString();
                case (int)TagEnum.SingleFlieUpload:
                    return GetSingleFlieUploadControl(propertyName, model.Value, model.Tips, verify).ToString();
                case (int)TagEnum.MultipleFlieUpload:
                    return GetMultipleFlieUploadControl(propertyName, model.Value, model.Tips, verify).ToString();
                case (int)TagEnum.Hidden:
                    return GetHiddenControl(propertyName, model.Value, model.Tips, verify, model.Min, model.Max, disabled).ToString();
                case (int)TagEnum.Email:
                    return GetEmailControl(propertyName, model.Value, model.Tips, verify, model.Min, model.Max, disabled).ToString();

                case (int)TagEnum.Reference:
                    return GetReferenceControl(propertyName, model.Value, model.Tips, verify, model.Values).ToString();

                case (int)TagEnum.MultipleReference:
                    return GetMultipleReference(propertyName, model.Value, model.Tips, verify, model.Values).ToString();
                case (int)TagEnum.Supplier:
                    return GetSupplierControl(model.Attribute,propertyName, model.Value, model.Tips, verify, model.Values).ToString();
                case (int)TagEnum.Customer:
                    return GetCustomerControl(model.Attribute, propertyName, model.Value, model.Tips, verify, model.Values).ToString();
                case (int)TagEnum.Product:
                    return GetProductControl(propertyName, model.Value, model.Tips, verify, model.Values).ToString();

                case (int)TagEnum.RelatedCompany:
                    return GetRelatedCompanyControl(model.Attribute, propertyName, model.Value, model.Tips, verify, model.Values).ToString();

                case (int)TagEnum.Contact:
                    return GetContactControl(propertyName, model.Value, model.Tips, verify, model.DefaultValue).ToString();

                case (int)TagEnum.Position2:
                    return GetPositionControl(propertyName, model.Value, model.Tips).ToString();

                case (int)TagEnum.Employee2:
                    return GetEmployeeControl(propertyName, model.Value, model.Tips).ToString();

                case (int)TagEnum.Department2:
                    return GetDepartmentControl(propertyName, model.Value, model.Tips).ToString();

                case (int)TagEnum.CheckBox2:
                    return GetCheckBox2Control(propertyName, model.Value, model.Tips, verify, List, disabled).ToString();

                default:
                    return GetTextControl(propertyName, model.Value, className, model.Tips, verify, model.Min, model.Max, disabled).ToString();
            }
        }

        public static IHtmlContent MyEditorFor<TModel, TValue>(this IHtmlHelper<TModel> helper, Expression<Func<TModel, TValue>> expression, List<ListItem> List = null, bool disabled = false)
        {
            return MyEditorFor<TModel, TValue>(helper, expression, "", List, disabled);
        }
        public static IHtmlContent MyEditorFor<TModel, TValue>(this IHtmlHelper<TModel> helper, Expression<Func<TModel, TValue>> expression, string prefix, List<ListItem> List = null, bool disabled = false)
        {

            if (helper == null) throw new ArgumentNullException(nameof(helper));
            if (expression == null) throw new ArgumentNullException(nameof(expression));

            ModelExpressionProvider modelExpressionProvider = (ModelExpressionProvider)helper.ViewContext.HttpContext.RequestServices.GetService(typeof(IModelExpressionProvider));

            var modelExplorer = modelExpressionProvider.CreateModelExpression(helper.ViewData, expression);
            if (modelExplorer == null) throw new InvalidOperationException($"Failed to get model explorer for {modelExpressionProvider.GetExpressionText(expression)}");

            string propertyName = modelExplorer.Name;

            PropertyInfo pi = modelExplorer.Metadata.ContainerType.GetProperty(modelExplorer.Name);
            if(pi==null)//ListExtendField[0].Type 修复  Select 控件 错误
            {
                string[] param = modelExplorer.Name.Split(new string[] { "." }, StringSplitOptions.RemoveEmptyEntries);
                pi = modelExplorer.Metadata.ContainerType.GetProperty(param.LastOrDefault());
                propertyName = param.LastOrDefault();
            }
            var tagAttribute = pi.GetCustomAttributes(typeof(TagAttribute)).FirstOrDefault();
            if (tagAttribute == null) return new HtmlString("");

            string value = string.Empty;
            if (modelExplorer != null && modelExplorer.Model != null)
            {
                if(modelExplorer.Model is DateTime)
                {
                    value = ((DateTime)modelExplorer.Model).ToString("yyyy-MM-dd HH:mm:ss");
                }
                else
                {
                    value = modelExplorer.Model.ToString();
                }
                
            }

            TagAttribute myTag = (TagAttribute)tagAttribute;

            if (myTag.MyType!=null&&myTag.MyType.FullName == "OA.Model.MyAttribute.TagEnum")
            {
                List<string> itemType = new List<string>() { "68", "69", "70", "26" };
                List<string> topType = new List<string>() { "13", "14", "15", "16", "17", "18", "20", "22", "23", "24", "26", "31" };
                if (prefix.StartsWith("TableFields"))
                {
                    myTag.DBScore = myTag.DBScore.Where(m => !topType.Contains(m.Value)).ToList();
                }
                else
                {
                    myTag.DBScore = myTag.DBScore.Where(m => !itemType.Contains(m.Value)).ToList();
                }
            }
            if (List == null && myTag.DBScore != null)
            {
                List = myTag.DBScore.Select(m => new ListItem() { Value = m.Value, Text = m.Text }).ToList();
            }
            
            if (!string.IsNullOrWhiteSpace(prefix))
            {
                propertyName = prefix + propertyName;
            }

            //tableValues.RowValues[0].CellValues.__StartLocation
            //dicExtend._K
            //Title
            string className = string.Empty;
            if (propertyName.StartsWith("dicExtend."))
            {
                className = propertyName.Replace("dicExtend.", "");
            }
            else if (propertyName.StartsWith("tableValues"))
            {
                int lastIndex = propertyName.LastIndexOf("__");
                className = propertyName.Substring(lastIndex);
            }
            else
            {
                className = propertyName;
            }

            switch (myTag.TagName)
            {
                case TagEnum.Text:
                    return GetTextControl(propertyName, value, className, myTag.Tips, myTag.Verify, myTag.MinLength, myTag.MaxLength, disabled);
                case TagEnum.ReadOnly:
                    return GetReadOnlyControl(propertyName, value, className, myTag.Tips, myTag.Verify, myTag.MinLength, myTag.MaxLength, disabled);
                case TagEnum.Number:
                    return GetNumberControl(propertyName, value, className, myTag.Tips, myTag.Verify, myTag.MinLength, myTag.MaxLength, disabled);
                case TagEnum.Money:
                case TagEnum.Subtotal:
                    return GetMoneyControl(propertyName, value, className, myTag.Tips, myTag.Verify, myTag.MinLength, myTag.MaxLength, disabled);
                case TagEnum.PassWord:
                    return GetPassWordControl(propertyName, value, className, myTag.Tips, myTag.Verify, disabled);
                case TagEnum.Select:
                    return GetSelectControl(propertyName, value, className, myTag.Tips, myTag.Verify, List, "", disabled);
                case TagEnum.Select2:
                    return GetNumberSelectControl(propertyName, value, className, myTag.Tips, myTag.Verify, List, "", disabled);
                case TagEnum.Radio:
                    return GetRadioControl(propertyName, value, myTag.Tips, myTag.Verify, List, disabled);
                case TagEnum.CheckBox:
                    return GetCheckBoxControl(propertyName, value, myTag.Tips, myTag.Verify, List, disabled);
                case TagEnum.Switch:
                    return GetSwitchControl(propertyName, value, myTag.Tips, myTag.Verify, disabled);
                case TagEnum.Date:
                    return GetDateControl(propertyName, value, className, myTag.Tips, myTag.Verify);
                case TagEnum.Time:
                    return GetTimeControl(propertyName, value, className, myTag.Tips, myTag.Verify);
                case TagEnum.DateTime:
                    return GetDateTimeControl(propertyName, value, className, myTag.Tips, myTag.Verify, disabled);

                case TagEnum.YearMonth:
                    return GetYearMonthControl(propertyName, value, className, myTag.Tips, myTag.Verify);
                case TagEnum.Year:
                    return GetYearControl(propertyName, value, className, myTag.Tips, myTag.Verify);

                case TagEnum.Department:
                    return GetSelectDepartmentControl(propertyName, value, myTag.Tips, myTag.Verify, disabled);

                case TagEnum.Position:
                    return GetSelectPositionControl(propertyName, value, myTag.Tips, myTag.Verify, disabled);

                case TagEnum.Employee:
                    return GetSelectEmployeeControl(propertyName, value, myTag.Tips, myTag.Verify, disabled);


                case TagEnum.TextArea:
                    return GetTextAreaControl(propertyName, value, className, myTag.Tips, myTag.Verify, disabled);
                case TagEnum.RichTextEditor:
                    return GetRichTextEditorControl(propertyName, value, myTag.Tips, myTag.Verify, disabled);
                case TagEnum.SingleImageUpload:
                    return GetImageUploadControl(propertyName, value, myTag.Tips, myTag.Verify, false);
                case TagEnum.MultipleImageUpload:
                    return GetImageUploadControl(propertyName, value, myTag.Tips, myTag.Verify, true);
                case TagEnum.SingleFlieUpload:
                    return GetSingleFlieUploadControl(propertyName, value, myTag.Tips, myTag.Verify);
                case TagEnum.MultipleFlieUpload:
                    return GetMultipleFlieUploadControl(propertyName, value, myTag.Tips, myTag.Verify);
                case TagEnum.Hidden:
                    return GetHiddenControl(propertyName, value, myTag.Tips, myTag.Verify, myTag.MinLength, myTag.MaxLength, disabled);

                case TagEnum.Email:
                    return GetEmailControl(propertyName, value, myTag.Tips, myTag.Verify, myTag.MinLength, myTag.MaxLength, disabled);

                case TagEnum.Reference:
                    return GetReferenceControl(propertyName, value, myTag.Tips, myTag.Verify, myTag.Values);

                case TagEnum.MultipleReference:
                    return GetMultipleReference(propertyName, value, myTag.Tips, myTag.Verify, myTag.Values);

                case TagEnum.Supplier:
                    return GetSupplierControl(propertyName,propertyName, value, myTag.Tips, myTag.Verify, myTag.Values);
                case TagEnum.Customer:
                    return GetCustomerControl(propertyName,propertyName, value, myTag.Tips, myTag.Verify, myTag.Values);
                case TagEnum.Product:
                    return GetProductControl(propertyName, value, myTag.Tips, myTag.Verify, myTag.Values);

                case TagEnum.RelatedCompany:
                    return GetRelatedCompanyControl(propertyName,propertyName, value, myTag.Tips, myTag.Verify, myTag.Values);

                case TagEnum.Position2:
                    return GetPositionControl(propertyName, value, myTag.Tips);

                case TagEnum.Employee2:
                    return GetEmployeeControl(propertyName, value, myTag.Tips);

                case TagEnum.Department2:
                    return GetDepartmentControl(propertyName, value, myTag.Tips);

                case TagEnum.CheckBox2:
                    return GetCheckBox2Control(propertyName, value, myTag.Tips, myTag.Verify, List, disabled);

                default:
                    return GetTextControl(propertyName, value, className, myTag.Tips, myTag.Verify, myTag.MinLength, myTag.MaxLength, disabled);

            }
        }

        public static IHtmlContent GetMultipleReference(string name, string value, string tips, string verify, string values)
        {

            string itemID = name.Replace(".", "_").Replace("[", "_").Replace("]", "_");
            string control = $"<input type=\"text\" id=\"{itemID}\"  autocomplete=\"off\" placeholder=\"{tips}\" class=\"layui-input {name} autocomplete\" style=\"max-width:190px;\" data-type=\"2\" data-name=\"{name}\" data-url=\"/Member/Home/GetReferences?param=" + values.ToBase62() + "\" / />";
            control += $"<table class=\"layui-table {itemID}Table\" style=\"max-width:800px;\">";
            control += @"<thead>
                            <tr><th style=""width:58px;"">No</th><th>Title</th><th style=""width:32px;"">#</th></tr>
                        </thead><tbody>";

            if (!string.IsNullOrWhiteSpace(value))
            {
                List<SimpleApproval> items = JsonHelper.DeserializeList<SimpleApproval>(value);
                if (items != null && items.Count > 0)
                {
                    int i = 0;
                    foreach (var item in items)
                    {
                        control += $"<tr><td>{item.No}<input type=\"hidden\" class=\"FormID\" value=\"{item.FormID}\" name=\"{name}[{i}].FormID\"/><input type=\"hidden\" class=\"Title\" value=\"{item.Title}\" name=\"{name}[{i}].Title\"/><input type=\"hidden\" class=\"CustomID\" value=\"{item.CustomID}\" name=\"{name}[{i}].CustomID\"/><input type=\"hidden\" class=\"Status\" value=\"1\" name=\"{name}[{i}].Status\"/><input type=\"hidden\" class=\"ID\" value=\"{item.No}\" name=\"{name}[{i}].No\"/></td><td>{item.Title}</td><td><span class=\"delete\">删除</span></td></tr>";
                        i++;
                    }
                }
            }

            control += "</tbody></table>";
 
            return new HtmlString(control);
        }

        public static IHtmlContent GetReferenceControl(string name, string value, string tips, string verify, string values)
        {
            SimpleReferences simpleReferences = null;
            if(!string.IsNullOrWhiteSpace(value))
            {
                simpleReferences = JsonHelper.DeserializeObj<SimpleReferences>(value);
            }
            if (simpleReferences == null) { simpleReferences = new SimpleReferences(); }
            else
            {
                simpleReferences.JsonInfo = JsonHelper.SerializeObject(new { CustomID = simpleReferences.CustomID, FormID = simpleReferences.FormID, No = simpleReferences.No, Title = simpleReferences.Title });
            }
            string itemID = name.Replace(".", "_").Replace("[", "_").Replace("]", "_");
            string control = $"<input type=\"hidden\" name=\"{name}\" class=\"mydata\" value=\"{simpleReferences.JsonInfo.ToBase64()}\" /> <input type=\"text\" id=\"{itemID}\"  autocomplete=\"off\" placeholder=\"{tips}\" class=\"layui-input {name} autocomplete\" value='{simpleReferences.Title}' data-type=\"1\" data-name=\"{name}\" data-url=\"/Member/Home/GetReferences?param=" + values.ToBase62() + "\" />";
            return new HtmlString(control);
        }

        public static IHtmlContent GetProductControl(string name, string value, string tips, string verify, string values)
        {
            ProductReferences productReferences = null;
            if (!string.IsNullOrWhiteSpace(value))
            {
                productReferences = JsonHelper.DeserializeObj<ProductReferences>(value);
            }
            if (productReferences == null) { productReferences = new ProductReferences(); }
            else
            {
                productReferences.JsonInfo = JsonHelper.SerializeObject(new { ID = productReferences.ID, Name = productReferences.Name });
            }
            string itemID = name.Replace(".", "_").Replace("[", "_").Replace("]", "_");
            string control = $"<input type=\"hidden\" name=\"{name}\" class=\"mydata\" value=\"{productReferences.JsonInfo.ToBase64()}\" /><input type=\"text\" id=\"{itemID}\"  autocomplete=\"off\" placeholder=\"{tips}\" class=\"layui-input {name} autocomplete\" value='{productReferences.Name}' data-type=\"5\" data-name=\"{name}\" data-url=\"/Member/Home/GetProduct\" />";

            return new HtmlString(control);
        }

        

        public static IHtmlContent GetProductsControl(string name, string value, string tips, string verify, string values)
        {

            string itemID = name.Replace(".", "_").Replace("[", "_").Replace("]", "_");
            string control = $"<input type=\"text\" id=\"{itemID}\"  autocomplete=\"off\" placeholder=\"{tips}\" class=\"layui-input {name} autocomplete MultipleProduct\" style=\"max-width:190px;\" data-name=\"{name}\" data-type=\"2\" data-url=\"/Member/Home/GetProduct\" />";
            control += $"<table class=\"layui-table {itemID}Table\" style=\"max-width:800px;\">";
            control += @"<thead>
                            <tr><th style=""width:58px;"">ID</th><th>Title</th><th style=""width:32px;"">#</th></tr>
                        </thead><tbody>";

            if (string.IsNullOrWhiteSpace(value))
            {
                List<BaseCustomForm> items = JsonHelper.DeserializeList<BaseCustomForm>(value);
                if (items != null && items.Count > 0)
                {
                    int i = 0;
                    foreach (var item in items)
                    {
                        control += $"<tr><td>{item.ID}<input type=\"hidden\" class=\"ID\" value=\"{item.ID}\" name=\"{name}[{i}].ID\"/><input type=\"hidden\" class=\"ID\" value=\"{item.Title}\" name=\"{name}[{i}].Title\"/><input type=\"hidden\" class=\"ID\" value=\"1\" name=\"{name}[{i}].Status\"/></td><td>{item.Title}</td><td><span class=\"delete\">删除</span></td></tr>";
                    }
                }
            }
            control += "</tbody></table>";
            return new HtmlString(control);
        }


        public static IHtmlContent GetSupplierControl(string attribute, string name, string value, string tips, string verify, string values)
        {
            RelatedReferences relatedReferences = null;
            if (!string.IsNullOrWhiteSpace(value))
            {
                relatedReferences = JsonHelper.DeserializeObj<RelatedReferences>(value);
            }
            if (relatedReferences == null) { relatedReferences = new RelatedReferences(); }
            else
            {
                relatedReferences.JsonInfo = JsonHelper.SerializeObject(new { ID = relatedReferences.ID, Name = relatedReferences.Name });
            }
            string itemID = name.Replace(".", "_").Replace("[","_").Replace("]", "_");
            string control = $"<input type=\"hidden\"  myattribute=\"{attribute}\" name=\"{name}\" class=\"mydata relevancy\" value=\"{relatedReferences.JsonInfo.ToBase64()}\" /><input myattribute=\"{attribute}\" type=\"text\" id=\"{itemID}\"  autocomplete=\"off\" placeholder=\"{tips}\" class=\"layui-input {name} autocomplete\" value='{relatedReferences.Name}' data-type=\"5\" data-url=\"/Member/Home/GetSupplier\" />";
            return new HtmlString(control);
        }

        public static IHtmlContent GetCustomerControl(string attribute, string name, string value, string tips, string verify, string values)
        {

            RelatedReferences relatedReferences = null;
            if (!string.IsNullOrWhiteSpace(value))
            {
                relatedReferences = JsonHelper.DeserializeObj<RelatedReferences>(value);
            }
            if (relatedReferences == null) { relatedReferences = new RelatedReferences(); }
            else
            {
                relatedReferences.JsonInfo = JsonHelper.SerializeObject(new { ID = relatedReferences.ID, Name = relatedReferences.Name });
            }
            string itemID = name.Replace(".", "_").Replace("[", "_").Replace("]", "_");
            string control = $"<input type=\"hidden\"  myattribute=\"{attribute}\" name=\"{name}\" class=\"mydata relevancy\" value=\"{relatedReferences.JsonInfo.ToBase64()}\" /><input myattribute=\"{attribute}\" type=\"text\" id=\"{itemID}\"  autocomplete=\"off\" placeholder=\"{tips}\" class=\"layui-input {name} autocomplete\" value='{relatedReferences.Name}' data-type=\"5\" data-url=\"/Member/Home/GetCustomer\" />";
            return new HtmlString(control);
            
        }

        public static IHtmlContent GetRelatedCompanyControl(string attribute, string name, string value, string tips, string verify, string values)
        {

            RelatedReferences relatedReferences = null;
            if (!string.IsNullOrWhiteSpace(value))
            {
                relatedReferences = JsonHelper.DeserializeObj<RelatedReferences>(value);
            }
            if (relatedReferences == null) { relatedReferences = new RelatedReferences(); }
            else
            {
                relatedReferences.JsonInfo = JsonHelper.SerializeObject(new { ID = relatedReferences.ID, Name = relatedReferences.Name });
            }
            string itemID = name.Replace(".", "_").Replace("[", "_").Replace("]", "_");
            string control = $"<input type=\"hidden\"  myattribute=\"{attribute}\" name=\"{name}\" class=\"mydata relevancy\" value=\"{relatedReferences.JsonInfo.ToBase64()}\" /><input myattribute=\"{attribute}\" type=\"text\" id=\"{itemID}\"  autocomplete=\"off\" placeholder=\"{tips}\" class=\"layui-input {name} autocomplete\" value='{relatedReferences.Name}' data-type=\"5\" data-url=\"/Member/Home/GetRelatedCompany\" />";
            return new HtmlString(control);             
        }
        /// <summary>
        /// 
        /// </summary>
        /// <param name="name"></param>
        /// <param name="value"></param>
        /// <param name="tips"></param>
        /// <param name="verify"></param>
        /// <param name="defaultValue">保存公司控件的Key</param>
        /// <returns></returns>
        public static IHtmlContent GetContactControl(string name, string value, string tips, string verify, string defaultValue)
        {
            string itemID = name.Replace(".", "_").Replace("[", "_").Replace("]", "_");
            StringBuilder sb = new StringBuilder();
            sb.Append($"<select name=\"{name}\" lay-filter=\"{itemID}\" id=\"{itemID}\" class=\"myContact Contact_{defaultValue}\"  currentvalue='{value.ToBase64()}' >");
            sb.Append("</select>");
            return new HtmlString(sb.ToString());
        }
        

        public static IHtmlContent GetEmailControl(string name, string value, string tips, string verify, int minLenth, int maxLength, bool disabled)
        {
            string itemID = name.Replace(".", "_");
            string maxLengthStr = "";
            if (maxLength > 0)
            {
                maxLengthStr = $"maxlength =\"{maxLength}\"";
            }

            string control = string.Empty;
            if (disabled)
            {
                control = $"<input type=\"text\" name=\"{name}\" id=\"{itemID}\" {maxLengthStr} minlength=\"{minLenth}\"  lay-verify=\"{verify}|myText|email\" autocomplete=\"off\" placeholder=\"{tips}\" class=\"layui-input {name}\" value=\"{value}\" style=\"width:190px;\" disabled=\"disabled\" />";
            }
            else
            {
                control = $"<input type=\"text\" name=\"{name}\" id=\"{itemID}\" {maxLengthStr}  minlength=\"{minLenth}\" lay-verify=\"{verify}|myText|email\" autocomplete=\"off\" placeholder=\"{tips}\" class=\"layui-input {name}\" value=\"{value}\" style=\"width:190px;\" />";
            }
            return new HtmlString(control);
        }

        public static IHtmlContent GetHiddenControl(string name, string value, string tips, string verify, int minLenth, int maxLength, bool disabled)
        {
            string itemID = name.Replace(".", "_");
            string maxLengthStr = "";
            if (maxLength > 0)
            {
                maxLengthStr = $"maxlength =\"{maxLength}\"";
            }

            string control = string.Empty;
            if (disabled)
            {
                control = $"<input type=\"hidden\" name=\"{name}\" id=\"{itemID}\" {maxLengthStr} minlength=\"{minLenth}\"  lay-verify=\"{verify}|myText\" autocomplete=\"off\" placeholder=\"{tips}\" class=\"layui-input {name}\" value=\"{value}\" disabled=\"disabled\" style=\"max-width:190px;\"  />";
            }
            else
            {
                control = $"<input type=\"hidden\" name=\"{name}\" id=\"{itemID}\" {maxLengthStr}  minlength=\"{minLenth}\" lay-verify=\"{verify}|myText\" autocomplete=\"off\" placeholder=\"{tips}\" class=\"layui-input {name}\" value=\"{value}\" style=\"max-width:190px;\" />";
            }
            return new HtmlString(control);
        }


        public static IHtmlContent GetTextControl(string name, string value, string className, string tips, string verify, int minLenth, int maxLength, bool disabled)
        {
            string itemID = name.Replace(".", "_");
            string maxLengthStr = "";
            if (maxLength > 0)
            {
                maxLengthStr = $"maxlength =\"{maxLength}\"";
            }

            string control = string.Empty;
            if (disabled)
            {
                control = $"<input type=\"text\" name=\"{name}\" id=\"{itemID}\" {maxLengthStr} minlength=\"{minLenth}\"  lay-verify=\"{verify}|myText\" autocomplete=\"off\" placeholder=\"{tips}\" class=\"layui-input {className}\" value=\"{value}\" disabled=\"disabled\" />";
            }
            else
            {
                control = $"<input type=\"text\" name=\"{name}\" id=\"{itemID}\" {maxLengthStr}  minlength=\"{minLenth}\" lay-verify=\"{verify}|myText\" autocomplete=\"off\" placeholder=\"{tips}\" class=\"layui-input {className}\" value=\"{value}\" />";
            }
            return new HtmlString(control);
        }

        public static IHtmlContent GetReadOnlyControl(string name, string value, string className, string tips, string verify, int minLenth, int maxLength, bool disabled)
        {
            if (string.IsNullOrWhiteSpace(value))
            {
                return GetTextControl(name, value, className, tips, verify, minLenth, maxLength, disabled);
            }
            string itemID = name.Replace(".", "_");
            string maxLengthStr = "";
            if (maxLength > 0)
            {
                maxLengthStr = $"maxlength =\"{maxLength}\"";
            }

            string control = string.Empty;
            if (disabled)
            {
                control = $"<input type=\"text\" name=\"{name}\" id=\"{itemID}\" readonly=\"readonly\" {maxLengthStr} minlength=\"{minLenth}\"  lay-verify=\"{verify}|myText\" autocomplete=\"off\" placeholder=\"{tips}\" class=\"layui-input {className}\" value=\"{value}\" disabled=\"disabled\" />";
            }
            else
            {
                control = $"<input type=\"text\" name=\"{name}\" id=\"{itemID}\" readonly=\"readonly\" {maxLengthStr}  minlength=\"{minLenth}\" lay-verify=\"{verify}|myText\" autocomplete=\"off\" placeholder=\"{tips}\" class=\"layui-input {className}\" value=\"{value}\" />";
            }
            return new HtmlString(control);
        }

        public static IHtmlContent GetSelectEmployeeControl(string name, string value, string tips, string verify, bool disabled)
        {
            ///"{\"EmpID\":\"A0004\",\"EmpName\":\"陈伏罗\"}" +DepartmentID
            string temp = name.Replace(".", "_").Replace("[", "_").Replace("]", "_");
            int departmentID = 0;
            if(!string.IsNullOrWhiteSpace(value))
            {
                SimpleEmpInfo info = JsonHelper.DeserializeObj<SimpleEmpInfo>(value);
                if(info!=null)
                {
                    departmentID = info.DepartmentID;
                }
            }
            string control = $"<div class='myPosition' data-type='selectEmployee' id='Department_{temp}'></div><div class='myPosition myEmployee2' ><select id='{temp}' name='{name}'></select></div><script>InitEmployeeAndDepartment('Department_{temp}','{temp}','{departmentID}','{value.ToBase64()}')</script>";
            return new HtmlString(control);
        }

        public static IHtmlContent GetSelectPositionControl(string name, string value, string tips, string verify, bool disabled)
        {
            string temp = name.Replace(".", "_").Replace("[", "_").Replace("]", "_");
            string control = $"<div class='myPosition' id='Department_{temp}'></div><div class='myPosition myPosition2' ><select id='{temp}' name='{name}'></select></div><script>InitPositionAndDepartment('Department_{temp}','{temp}','{name}','{value}')</script>";
            return new HtmlString(control);
        }

        public static IHtmlContent GetSelectDepartmentControl(string name, string value, string tips, string verify, bool disabled)
        {
            string temp = name.Replace(".", "_").Replace("[", "_").Replace("]", "_");
            string control = $"<div class='myPosition' id='Department_{temp}'></div><script>InitDepartment($('#Department_{temp}'),'{value}','{name}')</script>";
            return new HtmlString(control);
        }



        public static IHtmlContent GetCalculateControl(string name, string value, string className, string tips, string verify, int min, int max, bool disabled)
        {
            string itemID = name.Replace(".", "_");
            string control = string.Empty;
            if (disabled)
            {
                control = $"<input type=\"number\" name=\"{name}\" id=\"{itemID}\" lay-verify=\"required|myNumber\" autocomplete=\"off\" placeholder=\"{tips}\" class=\"layui-input {className}\" value=\"{value}\" disabled=\"disabled\" />";
            }
            else
            {
                control = $"<input type=\"number\" name=\"{name}\" id=\"{itemID}\" lay-verify=\"required|myNumber\" autocomplete=\"off\" placeholder=\"{tips}\" class=\"layui-input {className}\" value=\"{value}\" />";
            }
            return new HtmlString(control);
        }
        public static IHtmlContent GetMoneyControl(string name, string value, string className, string tips, string verify, int min, int max, bool disabled)
        {
            string itemID = name.Replace(".", "_");
            string control = string.Empty;
            if (disabled)
            {
                control = $"<input type=\"number\" name=\"{name}\" id=\"{itemID}\" step=\"0.01\"  lay-verify=\"required|myNumber\" autocomplete=\"off\" placeholder=\"{tips}\" class=\"layui-input {className}\" value=\"{value}\" disabled=\"disabled\" style=\"max-width:190px;\" />";
            }
            else
            {
                control = $"<input type=\"number\" name=\"{name}\" id=\"{itemID}\" step=\"0.01\" lay-verify=\"required|myNumber\" autocomplete=\"off\" placeholder=\"{tips}\" class=\"layui-input {className}\" value=\"{value}\" style=\"max-width:190px;\" />";
            }
            return new HtmlString(control);
        }
        public static IHtmlContent GetNumberControl(string name, string value, string className, string tips, string verify, int min, int max, bool disabled)
        {
            string itemID = name.Replace(".", "_");
            string maxStr = "";
            if (max > 0)
            {
                maxStr = $"max =\"{max}\"";
            }

            string control = string.Empty;
            if (disabled)
            {
                control = $"<input type=\"number\" name=\"{name}\" id=\"{itemID}\" step=\"1\"  lay-verify=\"required|myNumber\" autocomplete=\"off\" placeholder=\"{tips}\" class=\"layui-input {className}\" value=\"{value}\" disabled=\"disabled\" style=\"max-width:190px;\" />";
            }
            else
            {
                control = $"<input type=\"number\" name=\"{name}\" id=\"{itemID}\" step=\"1\"  lay-verify=\"required|myNumber\" autocomplete=\"off\" placeholder=\"{tips}\" class=\"layui-input {className}\" value=\"{value}\" style=\"max-width:190px;\" />";
            }
            return new HtmlString(control);
        }

        public static IHtmlContent GetPassWordControl(string name, string value, string className, string tips, string verify, bool disabled)
        {
            string itemID = name.Replace(".", "_");
            string control = string.Empty;
            if (disabled)
            {
                control = $"<input type=\"password\" name=\"{name}\" id=\"{itemID}\"  lay-verify=\"{verify}\" autocomplete=\"off\" placeholder=\"{tips}\" class=\"layui-input {className}\" value=\"{value}\" disabled=\"disabled\" style=\"max-width:190px;\" />";
            }
            else
            {
                control = $"<input type=\"password\" name=\"{name}\" id=\"{itemID}\"  lay-verify=\"{verify}\" autocomplete=\"off\" placeholder=\"{tips}\" class=\"layui-input {className}\" value=\"{value}\" style=\"max-width:190px;\" />";
            }
            return new HtmlString(control);
        }

        public static IHtmlContent GetSelectControl(string name, string value, string className, string tips, string verify, Type type, bool disabled)
        {
            string itemID = name.Replace(".", "_");
            StringBuilder sb = new StringBuilder();
            if (disabled)
            {
                sb.Append($"<select name=\"{name}\" id=\"{itemID}\" lay-filter=\"{className}\" disabled=\"disabled\" class=\"{className}\" >");
            }
            else
            {
                sb.Append($"<select name=\"{name}\" id=\"{itemID}\" >");
            }
            var dic = EnumHelper.GetDictionary(type);

            foreach (var item in dic)
            {
                if (item.Key.ToString() == value)
                {
                    sb.Append($"<option value=\"{item.Key}\" selected>{item.Value}</option>");
                }
                else
                {
                    sb.Append($"<option value=\"{item.Key}\">{item.Value}</option>");
                }
            }

            sb.Append("</select>");
            return new HtmlString(sb.ToString());
        }

        /// <summary>
        /// 值为文本
        /// </summary>
        /// <param name="name"></param>
        /// <param name="value"></param>
        /// <param name="className"></param>
        /// <param name="tips"></param>
        /// <param name="verify"></param>
        /// <param name="list"></param>
        /// <param name="thirdPartyDataSource"></param>
        /// <param name="disabled"></param>
        /// <returns></returns>
        public static IHtmlContent GetSelectControl(string name, string value, string className, string tips, string verify, List<ListItem> list, string thirdPartyDataSource, bool disabled)
        {
            //tableValues.RowValues[0].CellValues.__StartLocation
            string tempID = name.Replace(".", "_");
            StringBuilder sb = new StringBuilder();
            if (disabled)
            {
                sb.Append($"<select name=\"{name}\" id=\"{tempID}\" lay-filter=\"{className}\" disabled=\"disabled\" class=\"{className}\" >");
            }
            else
            {
                sb.Append($"<select name=\"{name}\" id=\"{tempID}\" lay-filter=\"{className}\" class=\"{className}\" >");
            }
            sb.Append($"<option value=\"\">请选择</option>");
            if (list != null)
            {
                foreach (ListItem item in list)
                {
                    if (item.Value == value)
                    {
                        sb.Append($"<option value=\"{item.Value}\" selected>{item.Text}</option>");
                    }
                    else
                    {
                        sb.Append($"<option value=\"{item.Value}\">{item.Text}</option>");
                    }
                }
            }

            sb.Append("</select>");
            //搜索联动
            if (!name.StartsWith("tableValues") && !string.IsNullOrWhiteSpace(thirdPartyDataSource))
            {
                sb.Append(@"<script type=""text/javascript"">
                        var json_" + tempID + @" = " + thirdPartyDataSource + @";
                        layui.use('form', function () {
                            var form = layui.form;
                            form.on('select(" + className + @")', function (data) {
                                if($(data.elem).parent().hasClass(""layui-input-block""))
                                {
                                    $.each(json_" + tempID + @", function (index, info) {
                                        if (info.Value == data.value) {
                                            for (var key in info) {
                                                if ($(""#dicExtend_""" + @"+key).length > 0) { $(""#dicExtend_""" + @"+key).val(info[key]); }
                                            }
                                        }
                                    });
                                }
                            }); 
                        });    
                    </script>");
            }
            return new HtmlString(sb.ToString());
        }

        /// <summary>
        /// 值为数字
        /// </summary>
        /// <param name="name"></param>
        /// <param name="value"></param>
        /// <param name="className"></param>
        /// <param name="tips"></param>
        /// <param name="verify"></param>
        /// <param name="list"></param>
        /// <param name="thirdPartyDataSource"></param>
        /// <param name="disabled"></param>
        /// <returns></returns>
        public static IHtmlContent GetNumberSelectControl(string name, string value, string className, string tips, string verify, List<ListItem> list, string thirdPartyDataSource, bool disabled)
        {
            string itemID = name.Replace(".", "_");
            StringBuilder sb = new StringBuilder();
            if (disabled)
            {
                sb.Append($"<select name=\"{name}\" id=\"{itemID}\" lay-filter=\"{className}\" disabled=\"disabled\" class=\"{className}\" >");
            }
            else
            {
                sb.Append($"<select name=\"{name}\" id=\"{itemID}\" lay-filter=\"{name}\" >");
            }
            sb.Append($"<option value=\"0\">请选择</option>");
            if (list != null)
            {
                foreach (ListItem item in list)
                {
                    if (item.Value == value)
                    {
                        sb.Append($"<option value=\"{item.Value}\" selected>{item.Text}</option>");
                    }
                    else
                    {
                        sb.Append($"<option value=\"{item.Value}\">{item.Text}</option>");
                    }
                }
            }

            sb.Append("</select>");
            return new HtmlString(sb.ToString());
        }

        /// <summary>
        /// 值为文本
        /// </summary>
        /// <param name="name"></param>
        /// <param name="value"></param>
        /// <param name="tips"></param>
        /// <param name="verify"></param>
        /// <param name="list"></param>
        /// <param name="disabled"></param>
        /// <returns></returns>
        public static IHtmlContent GetRadioControl(string name, string value, string tips, string verify, List<ListItem> list, bool disabled)
        {

            string disabledStr = disabled ? "disabled=\"disabled\"" : "";
            StringBuilder sb = new StringBuilder();
            foreach (ListItem item in list)
            {
                if (item.Value == value)
                {
                    sb.Append($"<input {disabledStr} type=\"radio\" class=\"{name}\"  lay-verify=\"C_{name}\"  name=\"{name}\" value=\"{item.Value}\" title=\"{item.Text}\" checked />");
                }
                else
                {
                    sb.Append($"<input {disabledStr} type=\"radio\" class=\"{name}\"  lay-verify=\"C_{name}\" name=\"{name}\" value=\"{item.Value}\" title=\"{item.Text}\" />");
                }

            }
            return new HtmlString(sb.ToString());
        }

        /// <summary>
        /// 值为文本
        /// </summary>
        /// <param name="name"></param>
        /// <param name="value"></param>
        /// <param name="tips"></param>
        /// <param name="verify"></param>
        /// <param name="list"></param>
        /// <param name="disabled"></param>
        /// <returns></returns>
        public static IHtmlContent GetCheckBoxControl(string name, string value, string tips, string verify, List<ListItem> list, bool disabled)
        {
            string disabledStr = disabled ? "disabled=\"disabled\"" : "";
            List<string> selectItems = new List<string>();
            if(!string.IsNullOrWhiteSpace(value))
            {
                selectItems = value.Split(new string[] { "," }, StringSplitOptions.RemoveEmptyEntries).ToList();
            }
             
            StringBuilder sb = new StringBuilder();
            foreach (ListItem item in list)
            {
                if (selectItems.Contains(item.Text))
                {
                    sb.Append($"<input {disabledStr} type=\"checkbox\" lay-verify=\"C_{name}\" class=\"{name}\"  lay-skin=\"primary\"  name=\"{name}\" value=\"{item.Text}\" title=\"{item.Text}\" checked />");
                }
                else
                {
                    sb.Append($"<input {disabledStr} type=\"checkbox\" lay-verify=\"C_{name}\" class=\"{name}\" lay-skin=\"primary\"  name=\"{name}\" value=\"{item.Text}\" title=\"{item.Text}\" />");
                }

            }
            return new HtmlString(sb.ToString());
        }


        /// <summary>
        /// 值为文本
        /// </summary>
        /// <param name="name"></param>
        /// <param name="value"></param>
        /// <param name="tips"></param>
        /// <param name="verify"></param>
        /// <param name="list"></param>
        /// <param name="disabled"></param>
        /// <returns></returns>
        public static IHtmlContent GetCheckBox2Control(string name, string value, string tips, string verify, List<ListItem> list, bool disabled)
        {
            string id = name.Replace(".", "_").Replace("[", "_").Replace("]", "_");
            string values = JsonHelper.ToBase64(list);
            StringBuilder sb = new StringBuilder();
            sb.Append("<div id=\"" + id + "\" class=\"xm-select-demo\" data-tips=\"" + tips + "\" data-values=\"" + values + "\" data-value=\"" + value + "\" data-name=\"" + name + "\"></div>");
            return new HtmlString(sb.ToString());
        }



        public static IHtmlContent GetSwitchControl(string name, string value, string tips, string verify, bool disabled)
        {
            string disabledStr = disabled ? "disabled=\"disabled\"" : "";
            StringBuilder sb = new StringBuilder();
            if (value != null && (value == "1" || value.ToLower() == "true"))
            {
                sb.Append($"<input {disabledStr} type=\"checkbox\" class=\"{name}\"  name=\"{name}\" lay-skin=\"switch\" value=\"true\" lay-text=\"是|否\" checked />");
            }
            else
            {
                sb.Append($"<input {disabledStr} type=\"checkbox\" class=\"{name}\" name=\"{name}\" lay-skin=\"switch\" value=\"true\" lay-text=\"是|否\" />");
            }
            return new HtmlString(sb.ToString());
        }


        public static IHtmlContent GetDateControl(string name, string value, string className, string tips, string verify)
        {
            StringBuilder sb = new StringBuilder();
            string id = name.Replace(".", "_").Replace("[", "_").Replace("]", "_");
            sb.Append($"<input type=\"test\" name=\"{name}\" id=\"{id}\" lay-verify=\"date\" placeholder=\"{tips}\" value=\"{value}\" data-type=\"date\" class=\"layui-input mydate {className}\" autocomplete=\"off\" data-format=\"yyyy-MM-dd\"  />");
            return new HtmlString(sb.ToString());

        }


        public static IHtmlContent GetTimeControl(string name, string value, string className, string tips, string verify)
        {
            StringBuilder sb = new StringBuilder();
            string id = name.Replace(".", "_").Replace("[", "_").Replace("]", "_");
            sb.Append($"<input type=\"test\" name=\"{name}\" id=\"{id}\"  placeholder=\"{tips}\" value=\"{value}\" data-type=\"time\" class=\"layui-input mydate {className}\" autocomplete=\"off\" data-format=\"HH:mm\" />");
            return new HtmlString(sb.ToString());
        }


        public static IHtmlContent GetYearMonthControl(string name, string value, string className, string tips, string verify)
        {
            StringBuilder sb = new StringBuilder();
            string id = name.Replace(".", "_").Replace("[", "_").Replace("]", "_");
            sb.Append($"<input type=\"test\" name=\"{name}\" id=\"{id}\" lay-verify=\"date\" placeholder=\"{tips}\" value=\"{value}\" data-type=\"month\" class=\"layui-input mydate {className}\" autocomplete=\"off\" data-format=\"yyyyMM\" />");
            return new HtmlString(sb.ToString());
        }

        public static IHtmlContent GetYearControl(string name, string value, string className, string tips, string verify)
        {
            StringBuilder sb = new StringBuilder();
            string id = name.Replace(".", "_").Replace("[", "_").Replace("]", "_");
            sb.Append($"<input type=\"test\" name=\"{name}\" id=\"{id}\" placeholder=\"{tips}\" value=\"{value}\" data-type=\"year\" class=\"layui-input mydate {className}\" autocomplete=\"off\" data-format=\"yyyy\" />");             
            return new HtmlString(sb.ToString());
        }



        public static IHtmlContent GetDateTimeControl(string name, string value, string className, string tips, string verify, bool disabled)
        {
            string disabledStr = disabled ? "disabled=\"disabled\"" : "";
            StringBuilder sb = new StringBuilder();
            string id = name.Replace(".", "_").Replace("[", "_").Replace("]", "_");
            sb.Append($"<input {disabledStr} type=\"test\" name=\"{name}\" id=\"{id}\" lay-verify=\"datetime\" placeholder=\"{tips}\" value=\"{value}\" data-type=\"datetime\" class=\"layui-input mydate {className}\" data-format=\"yyyy-MM-dd HH:mm:ss\" autocomplete=\"off\" />");
            return new HtmlString(sb.ToString());
        }

        public static IHtmlContent GetTextAreaControl(string name, string value, string className, string tips, string verify, bool disabled)
        {
            string disabledStr = disabled ? "disabled=\"disabled\"" : "";
            StringBuilder sb = new StringBuilder();
            sb.Append($"<textarea {disabledStr} name=\"{name}\" id=\"{name}\" placeholder=\"{tips}\" lay-verify=\"{verify}\" class=\"layui-textarea {className}\">{value}</textarea>");
            return new HtmlString(sb.ToString());
        }

        public static IHtmlContent GetImageUploadControl(string name, string value, string tips, string verify, bool multiple)
        {
            string multipleStr = "true";
            List<string> listPic = new List<string>();
            if (multiple)//多图片上传
            {
                listPic = JsonHelper.DeserializeList<string>(value);
                if (listPic.Count == 0)
                {
                    listPic.Add("");
                }
            }
            else
            {
                multipleStr = "false";
                listPic.Add(value);
            }
            var tempName = name.Replace(".", "_").Replace("[", "_").Replace("]", "_");
            StringBuilder sb = new StringBuilder();
            sb.Append($"<div class=\"upload_img_btn\" id=\"btn_{tempName}\">选择文件</div>" +
                $"<div class=\"oss_images_list\">");
            foreach (string item in listPic)
            {
                string display = "inline-block";
                if (string.IsNullOrWhiteSpace(item))
                {
                    display = "none";
                }
                sb.Append($"<div class=\"item\" style='display:{display};margin-right:10px;'>" +
                $"<div style='position:relative;border:1px dotted #ccc'>" +
                $"<img class='myImg' src=\"{item}\" />" +
                $"<img class='delete' src=\"/img/delete.png\" />" +
                $"<input type=\"hidden\" value=\"{item}\" name=\"{name}\"/>" +
                $"</div>" +
                $"<div class=\"progress\">" +
                $"<div class=\"progress-bar\" role=\"progressbar\" aria-valuenow=\"0\" aria-valuemin=\"0\" aria-valuemax=\"100\" style=\"width: 0%;\">" +
                $"<span class=\"sr-only\"></span>" +
                $"</div>" +
                $"</div>" +
                $"</div>");
            }
            sb.Append($"</div>" +
            $"<script type=\"text/javascript\">" +
            $"UpLoadImageObj(\"btn_{tempName}\"," + multipleStr + ");</script>");
            return new HtmlString(sb.ToString());

        }

        public static IHtmlContent GetSingleFlieUploadControl(string name, string value, string tips, string verify)
        {
            string tempName = name.Replace(".", "_").Replace("[", "_").Replace("]", "_");
            StringBuilder sb = new StringBuilder();
            sb.Append($"<div class=\"upload_file_btn\" id=\"btn_{tempName}\" style='width:86px;float:left;'>选择文件</div><div class='input_div'><input type='text' name='{name}' value='{value}' class='layui-input' lay-verify='{verify}' autocomplete='off' /></div>" +
                $"<script type=\"text/javascript\">");

            sb.Append($"UpLoadFlieObj(\"{name}\",\"btn_{tempName}\", false);</script>");


            return new HtmlString(sb.ToString());
        }

        public static IHtmlContent GetMultipleFlieUploadControl(string name, string value, string tips, string verify)
        {
            var tempName = name.Replace(".", "_");
            List<string> listFlie = new List<string>();
            listFlie = JsonHelper.DeserializeList<string>(value);

            StringBuilder sb = new StringBuilder();
            sb.Append($"<div class=\"upload_file_btn\" id=\"btn_{tempName}\">选择文件</div><table class=\"layui-table\"><thead><tr><th>文件名</th><th style='width:120px;'>进度</th><th style='width:60px;'>状态</th><th style='width:60px;'>操作</th></tr></thead><tbody>");

            foreach (string item in listFlie)
            {
                sb.Append($"<tr><td><a href=\"{item}\" target=\"_blank\" >" + item + $"</a></td><td>100%</td><td>已上传</td><td><span class='deleteAttachment'>删除</span><input type=\"hidden\" name=\"{name}\" value=\"{item}\" /></td></tr>");
            }
            sb.Append(@"</tbody></table>" +
                $"<script type=\"text/javascript\">");

            sb.Append($"UpLoadFlieObj(\"{name}\",\"btn_{tempName}\", true);</script>");
            return new HtmlString(sb.ToString());
        }


        public static IHtmlContent GetRichTextEditorControl(string name, string value, string tips, string verify, bool disabled)
        {
            var tempName = name.Replace(".", "_");
            var div_id = $"div_{tempName}";
            StringBuilder sb = new StringBuilder();
            sb.Append($"<div id=\"{div_id}\">{value}</div><textarea id=\"{tempName}\" name=\"{name}\" style=\"display:none\">{value}</textarea>");
            sb.Append(@"
                <script type='text/javascript'>
                    const E = window.wangEditor;
                    const editor = new E('#" + div_id + @"');
                    const $text = $('#" + tempName + @"');
                    editor.config.onchange = function (html) {                       
                        $text.val(html)
                    }
                    editor.config.uploadImgServer = oss_Host;
                    editor.config.uploadImgParams = {
                        key: oss_Dir_RichText + '${filename}',
                        policy: oss_Policy_RichText,
                        OSSAccessKeyId: oss_Accessid_RichText,
                        callback: oss_CallbackBody_RichText,
                        success_action_status: 200,
                        signature: oss_Signature_RichText
                    };
                    editor.config.uploadImgMaxLength = 1;
                    editor.create();
                </script>
            ");
            return new HtmlString(sb.ToString());
        }



       


    }


}
